package play.coroutine.channel

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

var channel = Channel<String>()
fun main() = runBlocking {
    println("ok")

    CoroutineScope(Dispatchers.Default).launch {
        var i = 0
        while (i < 20) {
            channel.send("$i")
            i++
        }
    }
    CoroutineScope(Dispatchers.Default).launch {
        while (true) {
            println("-> ${channel.receive()}")
        }
    }

    while (true) {
        println("=> ${channel.receive()}")
    }
}